package ru.spb.osll.myfit.wikiverifier;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableStyle;
import ru.spb.osll.myfit.server.Converter;
import ru.spb.osll.myfit.server.parser.PageParser;
import ru.spb.osll.myfit.server.parser.PageParserUtils;
import ru.spb.osll.myfit.util.CollectionUtils;
import ru.spb.osll.myfit.wikiverifier.result.TableVerificationResult;
import ru.spb.osll.myfit.wikiverifier.result.VerificationResultType;

public class SuggestionProviderTest {
	private PageParser m_parser = new PageParser(new Converter());

	@Test
	public void testSuggestionProvider() throws Exception {
		Table oneLineTemplate = m_parser.createTable(
				TableStyle.ONE_LINE_FIXTIRE,
				"enable advanced retention on clusters");
		Table setUpTemplate = m_parser.createTable(TableStyle.SETUP_FIXTURE,
				"cluster list", PageParser.LINE_SEPARATOR, "name",
				"ip address", PageParser.LINE_SEPARATOR, "cluster1", "1.2.3.4");
		SuggestionProvider suggestionProvider = new SuggestionProvider(
				CollectionUtils.list(oneLineTemplate, setUpTemplate));

		Table oneLineTable = m_parser.createTable(TableStyle.ONE_LINE_FIXTIRE,
				"|enable retention on clusters|");
		TableVerificationResult res = new TableVerificationResult(
				VerificationResultType.FAILURE, oneLineTable, "");
		suggestionProvider.provideSuggestion(res);
		PageParserUtils.printSuggestion(res, System.out);
		assertEquals("|enable advanced retention on clusters|\n",
				PageParserUtils.tableToString(res.getSuggestion()).replaceAll("\r", ""));

		Table setUpTable = m_parser.createTable(TableStyle.SETUP_FIXTURE,
				"clust list", PageParser.LINE_SEPARATOR, "nam", "ip addr",
				PageParser.LINE_SEPARATOR, "cluster1", "1.2.3.4");
		res = new TableVerificationResult(VerificationResultType.FAILURE,
				setUpTable, "");
		suggestionProvider.provideSuggestion(res);
		PageParserUtils.printSuggestion(res, System.out);
		assertEquals("|cluster list|\n|name|ip address|\n|cluster1|1.2.3.4|\n",
				PageParserUtils.tableToString(res.getSuggestion()).replaceAll("\r", ""));
	}
}
